package com.yanqu.road.server.cmd.activity.flowerstudy;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.flowerstudy.CrossFlowerStudyMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_FLOWER_STUDY_EXAM_START_MATCHING,desc = "花城书房开始匹配")
public class CrossFlowerStudyStartMatchingCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        FlowerStudyProto.CrossFlowerStudyExamMatchingStartReq req = FlowerStudyProto.CrossFlowerStudyExamMatchingStartReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        int roomType = req.getRoomType();
        if (req.hasUserBaseInfo()){
            UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(req.getUserBaseInfo());
            CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(),userBaseInfo);
        }
        FlowerStudyProto.FlowerStudyExamMatchingStartResp.Builder builder = CrossFlowerStudyMgr.startMatching(activityId, roomType, packet.getPlayerId(),(int)serverId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_FLOWER_STUDY_EXAM_MATCHING_START_FROM_CROSS,builder);
        MessageHelper.sendPacket(serverId,packet.getPlayerId(),pbMsg);

    }

    @Override
    public void sendData() {

    }
}
